

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;


import org.carrot2.examples.ConsoleFormatter;
import org.carrot2.examples.clustering.*;

import checkLocation.location;

public class debugApp extends HttpServlet {
  public void doGet(HttpServletRequest request,
                    HttpServletResponse response)
      throws ServletException, IOException {
	  response.setContentType("text/html");
    PrintWriter out = response.getWriter();    
    out.println();   
    debug abc=new debug();       
    String on=(request.getParameter("on")==null)?"t":request.getParameter("on");
    String source=(request.getParameter("source")==null)?"all":request.getParameter("source");
    boolean postProcessingCluster=(request.getParameter("cluster")==null)?false:true;
    boolean postProcessingCapCount=(request.getParameter("capcount")==null)?false:true;
    boolean intent=(request.getParameter("intent")==null)?false:true;
    int iL=Integer.parseInt((request.getParameter("intentLimit")==null)?"5":request.getParameter("intentLimit")); //intentLimit
    float pCC=Float.parseFloat((request.getParameter("pcc")==null)?"0.0":request.getParameter("pcc"));//postClusteringCovearge
    boolean reMerge=(request.getParameter("rm")==null)?false:true; //reMerge the postSubclusters depending upon the same name...
    boolean galleries=(request.getParameter("gallery")==null)?false:true; //reMerge the postSubclusters depending upon the same name...
    int  postProcess=(request.getParameter("stiching")==null)?0:Integer.parseInt(request.getParameter("stiching")); //reMerge the postSubclusters depending upon the same name...
    boolean naiveStiching=false;
    boolean queryBasedStiching=false;
    
    
    switch(postProcess){
    	case 1:naiveStiching=true;break;
    	case 2:queryBasedStiching=true;break;
    
    }
    
    
    String time1=(request.getParameter("time")==null)?null:request.getParameter("time");
    boolean time;
    long days=0;
    long hours=0;
    long minutes=0;
    
    if(time1==null){
    	time=false;
    	
    	
    	
    }
    else{
    	time=true;
    	char c;
    	int i=0;
    	int calc=0;
    	
    	while(i<time1.length()){
    		c=time1.charAt(i);
    		if(c=='d'||c=='D'){
    			days=calc;
    			calc=0;
    			//assign date
    		}
    		else if(c=='h'||c=='H'){
    			hours=calc;
    			calc=0;
    			//
    		}
    		else if(c=='m'||c=='M'){
    			minutes=calc;
    			calc=0;
    			//minutes
    		}
    		else if(c>=48&&c<=57)
    			calc=calc*10+(c-48);
    		else
    			System.err.println("error in parsing");
    		i++;
    	}
    }
    	
    
    
    
    System.out.println("Query "+request.getParameter("query"));
    String queryTemp="";
    if(request.getParameter("query")==null){
    	queryTemp="";
    }
    else{
    	queryTemp=request.getParameter("query");
    }
    
    
    

    System.out.println(intent);
    try{
    	
    		
    		abc.clusterDocuments(queryTemp,Integer.parseInt(request.getParameter("limit")),on,source,postProcessingCluster,postProcessingCapCount,intent,iL,pCC,reMerge,galleries,naiveStiching,queryBasedStiching,time,days,hours,minutes);
    		
    		out.print("done!");
    		
    }catch(Exception e){

    	
    	}
    
    /*System.out.println(abc.abc.Location.keySet().size());
    out.println("Location wise details");
	for(String key:abc.abc.Location.keySet()){
		if(location.checkLocation(key)==1)
		    		out.println(key+":"+abc.abc.Location.get(key));
		    }*/
	
    }    
  }

